
# clear workspace
rm(list=ls())
cat("\f")

# Relevant paths
labpath=file.path('C:','Users','user','Documents','Portfolio_Allocation')
setwd(labpath)

# install packages

library(foreign)
library(lmtest)
library(sandwich)
library(stargazer)

# import data
data<-read.dta('data_stata_pp.dta') #data<-data_stata_pp

data$port <- data$party_port2/data$gov_port2
data$seat <- data$party_seats/data$gov_seats

data$parliamentary <- NA
data$parliamentary[data$presidential == 1] <- 0
data$parliamentary[data$presidential == 0] <- 1

## Main Models

# No bargaining institutions variables

mod1.1 <- lm(port ~ seat + formateur + parliamentary + seat*parliamentary + formateur*parliamentary, data)
mod1.1

stargazer(mod1.1,coeftest(mod1.1,vcovCL,cluster=data$cabinetcode), type='text')

lmtest::dwtest(mod1.1) #Durbin-Watson Test

# Legislature power

mod2.1 <- lm(port ~ seat + formateur + legpower + parliamentary + seat*legpower + formateur*legpower +
               seat*parliamentary + formateur*parliamentary + legpower*parliamentary +
               seat*legpower*parliamentary + formateur*legpower*parliamentary, data)
mod2.1

stargazer(mod2.1, coeftest(mod2.1, vcovCL, cluster=data$cabinetcode),type='text')

lmtest::dwtest(mod2.1) #Durbin-Watson Test

# Party institutionalization

mod3.1 <- lm(port ~ seat + formateur + party_inst + parliamentary + seat*party_inst + formateur*party_inst +
               seat*parliamentary + formateur*parliamentary + party_inst*parliamentary +
               seat*party_inst*parliamentary + formateur*party_inst*parliamentary, data)
mod3.1

stargazer(mod3.1, coeftest(mod3.1, vcovCL, cluster=data$cabinetcode),type='text')

lmtest::dwtest(mod3.1) #Durbin-Watson Test

# Veto players

mod4.1 <- lm(port ~ seat + formateur + h_polcon5_vdem + parliamentary + seat*h_polcon5_vdem + formateur*h_polcon5_vdem +
               seat*parliamentary + formateur*parliamentary + h_polcon5_vdem*parliamentary +
               seat*h_polcon5_vdem*parliamentary + formateur*h_polcon5_vdem*parliamentary, data)
mod4.1

stargazer(mod4.1, coeftest(mod4.1, vcovCL, cluster=data$cabinetcode),type='text')

lmtest::dwtest(mod4.1) #Durbin-Watson Test

## Fixed Models

# No bargaining institutions variables

mod1.2 <- lm(port ~ seat + formateur + parliamentary + seat*parliamentary + formateur*parliamentary + factor(countryname), data)
mod1.2

stargazer(mod1.2,coeftest(mod1.2,vcovCL,cluster=data$countryname), type='text')

# Legislature power

mod2.2 <- lm(port ~ seat + formateur + legpower + parliamentary + seat*legpower + formateur*legpower +
               seat*parliamentary + formateur*parliamentary + legpower*parliamentary +
               seat*legpower*parliamentary + formateur*legpower*parliamentary + factor(countryname), data)
mod2.2

stargazer(mod2.2, coeftest(mod2.2, vcovCL, cluster=data$countryname),type='text')

# Party institutionalization

mod3.2 <- lm(port ~ seat + formateur + party_inst + parliamentary + seat*party_inst + formateur*party_inst +
               seat*parliamentary + formateur*parliamentary + party_inst*parliamentary +
               seat*party_inst*parliamentary + formateur*party_inst*parliamentary + factor(countryname), data)
mod3.2

stargazer(mod3.2, coeftest(mod3.2, vcovCL, cluster=data$countryname),type='text')

# Veto Players

mod4.2 <- lm(port ~ seat + formateur + h_polcon5_vdem + parliamentary + seat*h_polcon5_vdem + formateur*h_polcon5_vdem +
                seat*parliamentary + formateur*parliamentary + h_polcon5_vdem*parliamentary +
                seat*h_polcon5_vdem*parliamentary + formateur*h_polcon5_vdem*parliamentary + factor(countryname), data)
mod4.2

stargazer(mod4.2, coeftest(mod4.2, vcovCL, cluster=data$countryname),type='text')

